import 'package:base_plugin/base_plugin.dart';
import 'package:finance_app/src/common/app_colors.dart';
import 'package:finance_app/src/utils/input_formatter_tools.dart';
import 'package:finance_app/src/widgets/form/form_edit_status_inherited_widget.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

class CpfInputField extends StatelessWidget {
  final String title;
  final String hintText;
  final TextEditingController controller;
  final bool hasBottomBorder;
  final int level;
  final List<TextInputFormatter> inputFormatters;

  const CpfInputField(
      {Key key,
      @required this.controller,
      @required this.title,
      this.hasBottomBorder = true,
      this.inputFormatters,
      this.level = 1,
      this.hintText = '0.00'})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    bool isEdit = FormEditStatusInheritedWidget.ofEnable(context);

    return Container(
      padding: EdgeInsets.only(left: (20 * level).toDouble(), right: 20),
      decoration: BoxDecoration(
        border: hasBottomBorder
            ? Border(
                bottom: BorderSide(
                  color: aceGrayColor,
                  width: getDp(0.5),
                ),
              )
            : null,
      ),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          Text(
            title,
            style: TextStyle(fontSize: 15),
          ),
          Expanded(
            child: TextFormField(
              controller: controller,
              inputFormatters: inputFormatters == null
                  ? [doubleLimit2InputFormatter]
                  : inputFormatters,
              keyboardType: TextInputType.number,
              textAlign: TextAlign.right,
              scrollPadding: EdgeInsets.zero,
              enabled: isEdit,
              style: TextStyle(
                  fontSize: getSp(16),
                  color: isEdit ? aceBlueColor : aceBlackColor,
                  fontWeight: FontWeight.w700,
                  height: 14 / 16),
              decoration: InputDecoration(
                  isCollapsed: false,
                  border: InputBorder.none,
                  focusedBorder: InputBorder.none,
                  disabledBorder: InputBorder.none,
                  hintText: hintText,
                  hintStyle: TextStyle(
                      fontWeight: FontWeight.bold,
                      color: isEdit ? aceBlueColor : aceBlackColor,
                      fontSize: getSp(16),
                      height: 16 / 16),
                  labelStyle: TextStyle(
                      fontWeight: FontWeight.w400,
                      fontSize: getSp(16),
                      height: 16 / 16)),
            ),
          )
        ],
      ),
    );
  }
}
